﻿// using System.Collections;
// using System.Collections.Generic;
// using UnityEngine;
// using System;

// public class MovementComp : MonoBehaviour
// {

//     Action<Vector2> moveAction;
//     Vector2 moveDir;
//     public float speed;

//     Vector3 offSet;

//     public Camera camera;
//     void OnEnable()
//     {
//         Debug.Log("MovementComp.Enable");
//         moveDir = Vector2.zero;
//         moveAction = (dir) => { moveDir = dir; };
//         EventMgr.Instance.On("JoystickDir", moveAction);
//         offSet = new Vector3(0, 2, -5);
//     }

//     void OnDisable()
//     {
//         Debug.Log("MovementComp.Disable");
//         EventMgr.Instance.Off("JoystickDir", moveAction);
//     }
//     // Start is called before the first frame update
//     void Start()
//     {
        
//     }

//     // Update is called once per frame
//     void Update()
//     {
//         if(moveDir == Vector2.zero) return;
//         var dir = new Vector3(moveDir.x, 0, moveDir.y);
//         // transform.Translate(dir * speed * Time.deltaTime);
//         transform.position += dir * speed * Time.deltaTime;
//         //平滑旋转 方向向量
//         transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(dir), 0.1f);
//         Debug.Log("MovementComp.Update");
//     }

//     //相机跟随物体
//     void LateUpdate()
//     {
//         if(camera == null)
//         {
//             camera = Camera.main;
//             // camera.transform.SetParent(gameObject.transform);
//             // camera.transform.localPosition = offSet;
//             // camera.transform.localRotation = Quaternion.Euler(20, 0, 0);
//         }
//         camera.transform.position = transform.position + offSet;
//         camera.transform.LookAt(transform.position);
        
//     }

//     void OnDrawGizmos()
//     {
//         if (!camera) return;
//         Gizmos.color = Color.red;
//         Gizmos.DrawSphere(transform.position, 0.5f);
//         Gizmos.DrawLine(transform.position, camera.transform.position);
//     }
//     void OnDrawGizmosSelect()
//     {
//         if (!camera) return;
//         Gizmos.color = Color.red;
//         Gizmos.DrawSphere(transform.position, 0.5f);
//         Gizmos.DrawLine(transform.position, camera.transform.position);
//     }

//     void OnTriggerEnter(Collider other)
//     {
//         Debug.Log("MovementComp.OnTriggerEnter");
//     }

// }
